package com.inool.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.inool.mapper.AttendanceMapper;
import com.inool.model.Attendance;
import com.inool.model.Student;
import com.inool.service.AttendanceService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attendance> implements AttendanceService {

    @Autowired
    private AttendanceMapper attendanceMapper;
    
    @Override
    public Attendance addAttendance(Attendance attendance) {
        attendanceMapper.insert(attendance);        
        return attendance;
    }

    @Override
    public Attendance updateAttendance(Long id, Attendance attendance) {
        attendance.setAttendanceId(id);
        updateById(attendance);
        return attendance;
    }

    @Override
    public void deleteAttendance(Long id) {
        removeById(id);
    }

    @Override
    public Attendance getAttendanceById(Long id) {
        return getById(id);
    }

    @Override
    public List<Attendance> getAllAttendances() {
        return list();
    }

    @Override
    public List<Attendance> getAttendancesByStudentId(String studentId) {
        LambdaQueryWrapper<Attendance> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Attendance::getStudentNumber, studentId);
        return list(wrapper);
    }

    @Override
    public List<Attendance> getAttendancesByCourseId(String courseId) {
        QueryWrapper<Attendance> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id", courseId);
        return list(wrapper);
    }
}    